<style type="text/css">
.page h2.border{
	border-bottom: 1px solid #262B30;
	border-top: 1px solid #262B30;
	padding: 10px 0;
	font-size: 19px;
	margin-bottom:8px;
	color: #fff;
}
</style>

<?php 
$CI =& get_instance();
$CI->load->database();
$CI->load->model('register_model');
$CI->load->library("front/header_lib");
$package_detail = $CI->packages_model->get_package_detail_by_user_id($user_id);
//echo "__$user_id";debug($package_detail);exit;
$CI->header_lib->display_header_element(array("script"=>array("jquery-1.4.2"),"page_title"=>$title,"metakey_page"=>$metakey_page,"metadesc_page"=>$metadesc_page));
$CI->header_lib->display_header();
?>
<div id="container_wrapper">
  <div id="body_container">
    <div class="left_part">
    <?php echo $CI->header_lib->display_panel_left($data);?>
    
      
    </div>
    <div class="right_part">
        <div class="height10"></div>
        <h3 class="head03"></h3>
        <?php foreach($package_detail as $package)://debug($package);?>
        <div class="div013">
            <ul>
              <li style="padding-left: 10px;">
              <div class="">
                  <?php echo "<strong>".$package['name']."</strong>";?>
                  <?php echo "<br>".$package['offer_name'];?>
                  <?php echo $package['currency_type']." ".$package['cost'];?>
              </div>
              <div class="">
                  Posted On <?php echo $package['issue_date'];?>
              </div>
              <div class="">
                  Date expiring <?php echo $package['expire_date'];?>
              </div>
                  <div>
                      <?php echo "Status:";
                                        //debug($package);
                      $package_yes =$package_no = "";
                      if($package['status']==1) $package_yes = "checked";
                      else $package_no = " checked";

                      ;?>
                      <input type="hidden" value="<?php echo $package['id'];?>" name="package_id_<?php echo $package['id'];?>" id="package_id_<?php echo $package['id'];?>">
                      <input type="radio" value="0" <?php echo $package_no;?> name="package_yes_no_<?php echo $package['id'];?>" id="package_set_no_<?php echo $package['id'];?>">
                      <label for="package_set_no_<?php echo $package['id'];?>">Inactive</label>

                      <input type="radio" value="1" <?php echo $package_yes;?> name="package_yes_no_<?php echo $package['id'];?>" id="package_set_yes_<?php echo $package['id'];?>">
                      <label for="package_set_yes_<?php echo $package['id'];?>">Active</label>
                      <input type="button" onclick="change_package_status('<?php echo $package['id'];?>')" value="Update Status">
                      <span id="result_status_<?php echo $package['id'];?>"></span>
                  </div>
              </li>
              <li style="padding-left:10px;">
                  <div class="">
                      <a href="javascript:void(0);" class="toggleNext">Recharge Ads</a>
                      <div style="display:none;">
                          <form class="submit_recharge_ads" name="frm_recharge_ads_<?php echo $package['id'];?>" method="post" action="<?php echo "register/packages";?>">
                                <?php
                        $platinum_offers = $CI->register_model->get_package_offers('premium_ads');
                        foreach($platinum_offers as $key=>$platinum_offer) :
                        if($platinum_offer->special!=1 ){?>
                      <input name="packageList" type="radio" value="<?php echo $platinum_offer->id;?>" /><?php echo $platinum_offer->offer_name;?> (<?php if($platinum_offer->cost == 0) echo 'FREE'; else echo $platinum_offer->currency_type.'&nbsp;'.$platinum_offer->cost;?>)<br />
                        <?php } endforeach; ?>
                      <input type="hidden" value="<?php echo $user_id;?>" name="user_id" class="user_id">
                      <input type="hidden" value="<?php echo $package['expire_date'];?>" name="expire_date" class="expire_date">
                            <input type="submit" value="Recharge">
                            <span class="result_status" id="result_status_<?php echo $package['id'].$platinum_offer->id;?>"></span>

                          </form>
                      </div>
                  </div>
              </li>
          </ul>
       </div>
        <div class="height10px"></div>
        <?php endforeach;?>
        <!--<div class="div013">
            <ul>
                <li style="padding-left: 10px;"><input type="button" onclick="change_package_status()" value="Add More ads"></li>
            </ul>
        </div>-->
        <div class="height10"></div>
        <div class="clear">&nbsp;</div>
        <div id="cities_manage">
        <h3> Cities Manage</h3>
        <?php $this->session->set_userdata('payment_ses',random_string());
        //echo $this->session->userdata('payment_ses');
        
        ?>
        <div>
        <?php 
        if(!empty($province_list)){
         foreach($province_list as $province){?>
                             <?php echo $province['name']."<br>";?>
                             <?php }}?>
        </div>
        	<div class="div_list07">Cities:</div>
                    	<div class="div_list08">
                         <form method="post" name="frm_category" action="<?php echo current_url();?>">
                             	<select name="province_id" class="dir_select" style="width:181px;">
                                <option value="">Select cities</option>
                                <?php if(!empty($region_list)){
                              foreach($region_list as $key =>$value){
                             if($value['country'] == '2541')
                            $region_list_1[] = $value;
                            
                            if($value['country'] == '2540')
                            $region_list_2[] = $value;
 
                                             }
                            }
                            if(!empty($region_list_1)): ?><optgroup label="Standard Cities">
                                <?php foreach($region_list_1 as $key=>$value): ?>
                                <option value="<?php echo $value['id']?>" <?php echo ($company_detail['region_id']==$value['id'])?'selected':'';?>><?php echo $value['name'] ?></option>
                                <?php endforeach;?></optgroup>
                                <?php endif;
                             if(!empty($region_list_2)): ?><optgroup label="International Cities">
                                <?php foreach($region_list_2 as $key=>$value): ?>
                                <option value="<?php echo $value['id']?>" <?php echo ($company_detail['region_id']==$value['id'])?'selected':'';?>><?php echo $value['name'] ?></option>
                                <?php endforeach;?></optgroup>
                                <?php endif;
                             ?> 
                                </select>
                             <input type="hidden" name="directory_user_id" value="<?php echo $user_id;?>">
                             <input type="submit" value="Submit" name="submit_frm_cities"/>
                           </form> 
                        
                        </div>
                    	<div class="clear"></div>
        </div>
        <!-- FOR CATEGORY-->
         <div class="div013">
             <form method="post" name="frm_category" action="<?php echo current_url();?>">
                 <ul>
                     <li><h3> Category Manage</h3>
                     Please Note that for every category you choose it cost USD 20 each.
                     </li>
              <?php
              foreach($services_list as $key=>$value){
               if($value['services']=='Category')
              {
               ?><li>
                  <div class="div014">
                      <input type="checkbox" name="category[]"
                    <?php if(in_array($value['id'] , (array)$company_services)): ?>checked="checked" disabled="disabled" <?php endif; ?>
                    value="<?php echo $value['id'] ?>">
                    </div>
                  <div class="div015"><?php echo $value['name'] ?> <?php if(in_array($value['id'] , (array)$company_services)): ?>(This category is already in your list.) <a href="javascript:void(0);" onclick="remove_service_category_relation('<?php echo $user_id;?>','<?php echo $value['id'] ?>');">remove from list</a><?php endif; ?></div>
                  <div class="clear"></div>
                </li>
            <?php  }}?>
                <li>
                    <input type="hidden" name="payment_url" value="<?php echo current_url();?>">
                    <input type="hidden" value="<?php echo $user_id;?>" name="id_company" class="id_company">
                    <input type="submit" name="submit_frm_category" value="Submit">
                </li>
              </ul>
                
             </form>
         </div>
    </div>
  </div>
</div>

<?php
$CI->load->library("front/footer_lib");
$CI->footer_lib->display_footer();
$CI->footer_lib->display_footer_element();

?>
<script>
    function remove_service_category_relation(id_company, category_id){
        var answer = confirm("Are you sure you want to delete?");
        if(answer){
            $.ajax({
               url: '<?php echo site_url("directory_panel/remove_service_category_relation");?>'+'/'+id_company+'/'+category_id,
              success: function(data){
                  window.location.href = window.location.href;
              }
            });
        }else{
            return false;
        }
    }
    $('.toggleNext').click(function() {
        $(this).toggleClass('toggle_select');
        if($(this).hasClass('toggle_select')) $(this).html('Cancel Recharge'); else $(this).html('Recharge Ads');
        $(this).next().slideToggle();
    });
    $(".submit_recharge_ads").submit(function(){
         var checked_val = $('input:radio[name=packageList]:checked').val();
         var user_id = $(this).find('.user_id').val();
         var resultID = $(this).find('.result_status').attr('id');
         var prev_expire_date = $(this).find('.expire_date').val();
         $('#'+resultID).html('loading...');
         $.ajax({
              type: "POST",
             data:"user_id="+user_id+"&package_id="+checked_val+"&prev_expire_date="+prev_expire_date,
           url: '<?php echo site_url("directory_panel/recharge_directory_package");?>',
          success: function(data) {
              $("#"+resultID).html(data);
          }
        });
         return false;
        //$()
    });
    function change_package_status(package_id){
       var checked_val = $('input:radio[name=package_yes_no_'+package_id+']:checked').val();
      // alert(checked_val);
      // var package_id = $('#package_id_'+package_id).val();
       $('#result_status_'+package_id).html('loading...');
       $.ajax({
           url: '<?php echo site_url("directory_panel/change_package_status");?>/'+package_id+'/'+checked_val,
          success: function(data) {
              $('#result_status_'+package_id).html(data);
          }
        });
        
    }
</script>